//
// Created by lujun on 19-6-21.
//
#include "riscv_math.h"
#include <stdint.h>
#include <stdlib.h>
// #include "array.h"
#include "../common.h"

#include "../HelperFunctions/math_helper.c"
#include "../HelperFunctions/ref_helper.c"

#include <stdio.h>
#define DELTAF32 (0.05f)
#define DELTAQ31 (63)
#define DELTAQ15 (1)
#define DELTAQ7 (1)

#define ENABLE_ALL
#define NEGATE
#define OFFSET
#define SCALE
#define SHIFT
#define SUB

#define ARRAY_SIZE 257

int test_flag_error = 0;

int main()
{
    int i;

    /* clang-format off */
	float32_t f32_a_array[ARRAY_SIZE] = {
	52331.288433, -48577.168507, 37541.128682, 26659.310242, 7633.298190, 47316.037824, 84089.195625, 79745.946380, 40155.952076, 46563.196204, 44099.519321, 33011.037777, -35269.990235, 2872.005647, -12838.517627, -87521.031716, 50016.765012, -84521.559465, -67765.771700, 62680.699895, 68373.039960, -53632.691314, -74083.289779, -82973.898048, -59370.680537, -36973.033347, -94929.902292, 53786.361838, -45899.602558, -41248.686598, -43806.038501, 11002.909520, -2941.800784, 49730.775090, 91426.796942, -76039.873184, 58843.103285, -92438.838688, 96004.542320, 1554.960120, -66542.023915, -90053.450851, -46349.869299, -89358.804340, 58501.331357, -61726.872720, -19021.692386, -80410.920374, 59607.584952, -29940.851717, 81505.290356, -60937.795758, 10682.928851, -67737.313853, -57466.652143, 31505.823080, 92388.510223, 49761.443920, 96610.767675, 22256.440811, 16796.757241, 58298.853138, -24489.292791, 57233.903592, -40847.910484, 10359.367685, 83753.857690, 26415.461313, -77446.419844, -65849.698894, -65928.653292, 59254.601853, -46206.507304, -85111.036098, 66801.566764, -74938.948694, 65732.005771, 17326.005148, -309.993151, -79531.517004, -79029.333327, -2932.637044, 73984.743122, -81206.337558, 38289.233209, -73844.742306, 40960.150496, -7609.540504, 2401.131977, 76308.648178, -92505.468389, 71305.413217, -23037.348088, -73577.170036, 33086.154336, -45194.365110, -16542.993069, -14940.368757, 61054.722234, 42437.475020, -74651.166819, 53080.506990, 4980.415587, 48517.051470, -29991.366258, 99295.134177, 4451.464113, 56004.455071, -94324.235920, -51485.557159, 42940.493537, -12791.198267, -1770.403019, -62774.757604, -51482.431501, -86123.160142, 84076.715024, -43882.331214, 98448.478438, 81023.660745, 32947.073964, 21730.758103, 14718.088681, -52272.842985, -37985.478491, -12193.390249, -6122.464346, 7585.463115, 75203.959320, -8276.419329, 30419.691385, 99387.100328, -83704.984719, -17945.209460, 15860.785857, 55692.522582, -37014.516805, -35058.273893, -63270.591407, -71875.422740, -64843.383162, -52460.197925, -49788.105733, 41847.550664, 7039.609820, 60323.495478, -13105.425088, -28456.829635, -57621.930531, 77851.971584, -91071.463412, -35432.683524, -70638.512344, 20384.886551, 84816.865093, -18649.781348, 94104.828428, -16611.121410, 91323.723008, -9217.603410, -84232.250832, 44072.940747, -60470.771933, 47376.486542, 19785.643449, -74141.729284, -81806.848759, 34403.267913, -13973.165371, -48798.422802, -20894.039920, -38104.428921, -32488.142945, 4047.880293, -54026.109997, 99146.351590, -87810.892192, -29245.189835, -43464.327430, -12983.310076, -29775.234191, 65259.560103, 379.330207, -31178.333111, 78500.227741, -1872.495036, 93883.187587, 42445.673660, 76333.886537, 17394.628843, -16854.430580, 26596.133783, -15327.745771, -40010.595847, 53477.753118, 66216.627695, 63808.332473, -45209.605747, 61373.025107, -11226.800183, -15311.893268, 47484.245222, 94259.572273, 42402.273343, -2616.576467, 72938.046369, -57708.866182, 42473.217724, -31233.510291, -69096.584839, 40075.109015, 84795.600947, 55688.998872, 80012.203974, -28875.812190, -92635.007732, 71342.750304, -31988.280404, 47687.152546, -8496.759875, -70315.230444, 55389.932447, -36858.190582, -78150.660918, 96964.622124, -35788.274089, 97181.022610, -62662.599472, -40025.536726, 94309.502917, 78583.295615, 32561.432512, 30759.542053, -29127.825718, 39218.237061, 4236.728252, -49585.145204, -29642.945237, -63983.871887, 37449.022023, -62372.998789, 73842.986013, -28996.921064, 45289.518788, 68829.285430, 72548.129432, 91111.351457, 75128.996215, -19285.933410, -54055.665627, -5611.050417, -9911.675718, -4180.616322, -64614.763347, -23932.549428, -26566.954749, 0
	};
	float32_t f32_b_array[ARRAY_SIZE] = {
	-14748.363506, -52882.384680, 25759.674589, -8430.675902, 74296.471371, -43863.727703, -523.083136, -77357.923759, 32783.353464, 14412.111012, -71393.350919, -84183.651778, 824.589092, 5762.424446, 50730.438763, 48260.466707, -64545.815296, -39900.156962, -42110.612503, 56969.361004, -51774.608591, 9524.295477, -56397.699274, 32974.695621, 54630.484822, 90917.121406, 58344.534264, -29546.804178, 29363.527509, -87659.765721, -80490.876894, 37360.782533, 83452.673319, -19566.741800, -64002.115525, -86502.336497, -86006.512493, 80838.557374, -14739.922414, -16896.379687, 8249.474651, 62724.054497, -1554.008023, -20395.188880, -31156.347950, 79891.105230, -45867.738768, 41333.044629, -7676.999956, 21771.713145, 82557.192605, 30500.710863, 31020.717681, 90597.001881, 99010.508568, 30322.571728, 40948.345159, -56276.504473, -61883.945216, -43079.002095, 29078.509077, 22794.228547, 74372.378733, -44055.068256, -53388.492633, -47784.325626, 14655.815561, 87444.174577, 87769.374380, -68921.250204, -68386.761085, -52032.613959, 59823.419305, 1754.801055, 95175.314736, -81105.314495, -34347.237022, 99133.704956, -1084.496731, -7528.947275, -8550.169841, 96866.053124, -32186.038563, 36079.172067, -25788.868160, 57515.787963, -89526.285196, -77820.605829, 49394.787719, -35410.274156, -2256.085487, -83347.534826, -19993.092476, -65402.603615, -35246.742498, -22573.751524, 54198.764622, -12551.651641, 38204.923509, 98339.464040, -78764.691121, -2536.506110, 62301.390849, -85946.411564, 25842.028436, 76980.636907, 66949.171540, -29600.343091, -67253.179681, 7999.959469, 51332.669028, -44266.161876, 63008.256158, 49447.784664, -8380.123077, 46.292316, -67452.730308, 93632.612589, -81494.922442, 83208.281900, -77996.866742, 53254.044501, -2066.082186, 89818.784744, -15978.453803, -58657.785681, 30989.308148, 63421.056711, 68160.313136, -44862.375309, -91802.269653, -10308.420264, 94507.850245, 43351.597128, -1687.669472, 8944.333835, -42358.233628, -66830.639128, 31335.273026, 1305.552391, 90904.188061, 26056.581575, 76717.070907, 69598.252599, -29449.914625, 51436.373685, -15138.962974, 78186.487897, -54861.987172, 15103.224330, -72401.041527, -79902.737504, -11792.134683, 35998.732785, -17947.048577, -35121.453671, 95234.578361, 33760.262870, -49548.979357, 33613.590186, -59180.165768, -12312.964538, 68976.756638, -98421.925464, 18748.996727, 87649.415189, -42603.968561, 66093.151677, -72649.431024, 58901.864996, -67727.390125, -93153.696522, -49001.478199, 51765.998867, 83230.060919, -40058.643283, -95872.550493, 37144.776727, 95117.125646, -49387.279353, -24978.646538, 51620.351258, -22826.467093, -27834.035075, 58073.389064, 51847.867995, -86010.948205, -41612.180492, 69343.113867, -95211.627972, 50191.674724, 29427.473654, 25573.797740, -58615.487098, 54218.880235, -32891.418497, 98733.460752, -63682.034121, 12563.683345, -75141.721838, 15118.782568, 37524.587438, -73081.462512, 4141.596016, 19532.955276, -71059.521486, 83329.657219, 24808.360451, 49712.670973, 55451.749620, -9809.453314, -87943.676689, -34302.161571, -94239.070472, 12611.124712, -38415.464213, -10883.611425, 2520.958779, 77365.058601, -77828.961437, 40915.821395, -65590.466499, -44446.352196, 43511.623038, -67237.562075, 38946.545673, -56447.758311, 8714.617727, 99568.415968, -45626.895014, 95102.601971, 43532.618006, 52518.777936, -31728.780028, -20026.763246, 71735.294631, -79396.329375, -16707.811932, 57955.715055, 4169.562060, -69506.060979, -67552.113568, -36282.586949, -31273.361532, -18139.073474, -22958.638140, 3438.475837, 86574.556610, -93725.007343, 8368.616620, 1270.601154, -21430.484085, -98146.567789, 96054.887155, 79600.800101, 45881.525507, 0
	};
	q7_t q7_a_array[ARRAY_SIZE] = {
	-22, -117, 90, 77, 4, -73, 115, -93, 36, -25, -122, 12, -54, 113, 66, -122, -88, 20, 22, 70, -67, 6, 13, -42, 98, -80, 23, -94, 58, -62, 25, -116, -101, -80, 12, 10, -2, -90, -46, -118, -111, -120, 16, 8, 22, -65, 64, 70, 11, 86, -75, -19, -98, 49, 99, -89, -15, 125, 15, 5, 71, 98, -101, 34, -43, -73, -100, -127, 4, -39, -62, 83, -59, 68, -105, 52, 91, -22, 124, 17, -27, 47, -78, -82, 79, 49, -108, 41, 2, -85, -115, -27, -110, 21, -107, 49, -101, -108, 114, -4, -121, 32, -65, -30, -52, -92, -95, -111, 77, -12, 25, -43, -73, 15, 96, -11, 84, 28, 52, -97, -52, 46, 64, 11, 56, -10, -117, -116, 41, 93, -3, -19, 74, -28, -7, -86, 14, -116, 46, 113, 41, -99, -89, -53, 109, 78, 19, 16, 13, 112, 40, -46, -119, 120, -10, 23, 56, -126, 84, 32, 127, -114, -46, 124, 71, 56, 60, -101, 96, 94, -113, 70, -103, 69, 71, -120, -25, -78, 24, 39, 0, -63, -69, -65, -19, -52, -108, -78, -83, -108, 35, -70, 114, -91, -26, -24, 24, -20, 103, -126, 44, 112, 34, 18, 2, -30, 94, 29, 51, 116, -70, 58, -78, -15, -42, 43, 123, 43, -93, -11, -123, -35, -43, 109, -47, 34, 58, -75, -30, -98, -95, 47, 54, -25, -127, -40, 18, 8, -70, 122, -67, -9, 34, 126, 86, -1, -78, -118, 19, -69, -18, -108, 98, -8, 10, -99, 0
	};
	q7_t q7_b_array[ARRAY_SIZE] = {
	80, -7, 32, 18, 9, 28, -88, 74, -91, 30, -46, 49, 28, -37, -89, -63, -9, -69, -114, 6, 107, -12, -8, -29, 124, -113, 73, -31, 27, 12, 9, -49, 99, -79, -77, 59, -88, 71, -120, -20, -89, 1, -84, -26, 111, -54, -92, 105, 108, -83, -119, -30, 66, 2, -1, 40, -88, 53, 16, 85, 75, -122, -14, -53, -118, 78, 45, -8, -72, -52, 9, -63, -64, 64, -62, -125, -11, -71, 91, 36, -93, 74, 17, -97, 20, -56, 109, -33, -121, 104, -86, -21, -39, 2, -121, -72, 47, 47, 2, -123, 53, -104, -72, 8, 30, -18, 10, 104, -110, -83, 70, 34, -92, 32, -105, 70, 74, -57, 19, 109, -41, 17, 62, 80, 103, 98, 75, 118, 118, -54, 97, -93, 73, -112, -18, -50, -68, -10, -59, -112, 84, 100, -106, 70, 77, 114, -85, 104, 100, 53, -13, -18, -116, -74, -7, -116, 50, 77, -8, -27, 24, 28, -92, 68, 74, -119, 64, -30, -21, -35, -47, -13, -126, -27, 3, 83, -65, -126, -57, -116, -110, -105, 30, 45, -50, 108, -126, -83, 77, 90, 80, 84, 123, -49, -70, -3, 52, -20, -92, 8, 106, -101, -70, 105, -122, 50, -85, 21, 93, 85, -32, 31, -53, -5, 4, -88, -4, 87, 41, -27, -94, -26, -74, -47, 85, 10, -88, -94, 65, 34, 50, 121, -23, -68, -87, -93, -96, 26, 119, -83, -114, 50, -99, -61, -125, -107, -30, 98, 110, -81, 0, -94, -42, 21, -74, -35, 0
	};
	q15_t q15_a_array[ARRAY_SIZE] = {
	1982,1152,1883,65,2732,2402,2238,2440,1150,1852,1727,1591,826,746,1355,684,2414,2959,90,1607,262,2407,2968,201,2819,55,2052,2352,1603,2657,2698,1878,414,654,547,126,321,1850,2819,1064,1232,2954,2837,2030,2965,2301,1011,1988,733,887,2041,1584,1235,1808,2252,1751,1656,1751,1536,248,2159,2989,1064,2914,1040,2660,1365,1241,654,377,927,2179,2349,2082,30,2530,2767,2313,128,1135,2114,2189,673,808,2020,1433,1872,710,532,2489,2301,2804,324,547,298,1470,580,2688,298,133,1672,2318,936,537,1017,631,1531,2720,1887,305,1173,164,1504,1296,2993,2435,1457,2684,413,1171,2783,2753,2141,1856,1030,2809,375,2192,1940,2500,1195,2250,2506,968,1657,2938,1648,992,1859,1082,2270,1242,1478,2085,2919,984,2514,2218,2863,96,1071,1988,845,692,2134,1874,1772,1982,143,1047,1355,723,2146,2569,845,2194,414,2511,416,1765,1099,2421,1512,1469,2632,1060,1349,2891,127,2919,568,2002,1760,2026,1084,1861,2434,58,252,2925,1955,694,1211,367,806,774,995,457,1045,365,2653,283,2791,1198,143,1028,2208,2385,1635,2059,2681,165,911,139,587,2161,2166,2634,1748,213,2769,2402,858,1631,2955,2148,2517,1300,1412,1683,808,2248,1512,1941,924,417,1427,1088,2365,2341,2006,401,65,1680,903,2819,2943,860,2403,2689,1793,2653,2832,1648,2186,1731,78
	};
	q15_t q15_b_array[ARRAY_SIZE] = {
	1340,1939,1564,1117,2812,2489,2548,1118,1780,2618,2801,2006,621,1962,217,1221,2001,2802,2433,1454,2271,1252,2916,2964,2593,1167,1365,741,2354,2649,2742,1675,1797,447,2700,1352,618,2699,2288,2648,855,2020,1993,369,1222,826,2151,851,2689,2480,1171,1494,2085,2504,1829,1725,979,1370,2142,2654,2163,56,2025,1316,1314,352,2445,975,739,1029,1128,1640,1686,1188,1195,1547,1973,2853,2168,1201,2496,404,182,253,492,973,906,36,1620,287,440,1894,2578,2923,1713,2991,1661,1547,993,1291,1476,214,2664,194,1309,2480,1184,1841,2456,2659,2794,573,776,2694,1781,1512,1839,2459,1596,607,1362,1284,2899,1861,2087,2161,1041,1551,1671,470,1687,2085,1280,2509,2195,1081,1363,1160,2327,2203,1291,2082,2836,2353,2117,329,1170,1773,1379,152,687,2503,47,2592,235,2008,1501,654,1715,367,2014,1799,168,170,458,59,1306,2497,1853,1561,2592,294,2725,325,1551,430,1679,14,2301,2547,2751,2961,1516,815,303,1524,1757,2289,249,1985,1551,514,2816,1772,1322,2826,1968,1356,2520,1598,1662,2041,1102,718,1737,2601,1221,338,1332,901,1205,2501,1211,1171,1082,421,781,261,1289,772,893,1275,358,1486,2120,731,2356,223,1182,11,663,4,568,428,805,525,416,1797,2704,2819,664,1449,1129,1572,795,206,1309,522,79,2865,1292,2885,2288,23,2041,2118,1936
	};
	q31_t q31_a_array[ARRAY_SIZE] = {
	122675060, -19679606, 12005090, 128022795, -95284239, 1562872905, 214945602, 1304329431, -1508008274, 240787476, -905121314, 1622448750, 1128343957, 1088297819, 1929718262, 301748725, -1705937804, 412523122, 1868902555, 1990922011, 667241326, 1515133104, 122494706, -1539561650, 1117106510, 859507136, -940688492, -216177261, 1480104259, -634335848, 1983809950, -1406467930, -475661641, 1322061117, -825315378, -1807561254, 1449578423, 657148057, 1926668369, -1215598619, 412458663, -1807869491, 1422979790, 1023406889, -597431780, -1448317484, 1541343116, -2012852409, -43191490, -1215649277, -1017506653, -1915995397, -2080480350, 1094251372, 528600991, 143231710, 1391256474, -1041052209, 1278401986, 850686725, -2102619359, 1935527594, -431606953, -1976242055, -350139619, -589613336, 723038213, 166006808, 1760518450, 1386001502, -1457863745, -843865763, -1469590333, -605307148, -1892711295, 1107317389, 2133350043, 857819879, -798439008, -683125572, 1414380309, -1296729433, -972942965, -486754604, 428102856, -954668329, -2135465095, 1294752174, -2115260357, -1285371550, 142879568, -1259143073, 1988627270, 25731949, -1919745773, 1911174931, -835919509, -46679513, 275933135, 1724700061, 869122148, 473727312, -2018146537, 237804352, 145422132, 1233850002, -1329633347, 12780582, 1110157442, -1915661877, -928226928, -227663812, 828379127, -1674105026, 1927003415, -1639017283, -465311741, -658984229, -903260597, 490177562, 1126362032, -1034719085, -422641969, 1772346616, -1907663619, 1817734130, -1923639110, 1120016563, 141086779, -2102345903, 1724327426, -1866919811, -830684706, 1745078516, -1976128296, 799279002, -993799341, -1390877590, 904934458, -472067105, -455592220, 212192933, -34506575, 333518014, -85924850, -1599754424, 1355485624, -2014365016, -1127697814, -1076997804, 1705661182, -3234669, -632233921, 1798567554, -33103420, 4247767, -49163650, 779091592, -1163771871, 387580837, 127441404, 209878412, 61087762, 518500510, 836574845, 1629528554, -406038126, 459087674, -1103579310, 21540829, 1530951457, -1901138893, 809545038, -1083073633, -1608669130, -1714887885, 305376892, 905733099, 268734751, -1761301144, -1110601471, 581811091, 1926809483, 875843018, -409535295, -1494401242, -1492148258, 668320270, -1996003820, -470239924, 793927528, 1945752597, -336927405, -1078519032, 1673260004, -1226877022, 521095932, -572753832, 1860213970, 1198498531, 88542373, 1360949371, 656122057, 1792409478, 1656830983, -350299887, 1580672481, -1680928093, -2092549882, 876454682, -1735152678, 1646616771, 1189864260, 790291045, -337847342, 1947695906, -53101665, 1238647266, -89940713, -371577084, -1610381759, -402627031, 506455569, 430996275, 1774144323, 1310368600, -724205623, 370714565, 725347367, -1828596909, 365721697, -53655909, -1185780624, 1770739705, -2034892356, -418862235, 1739930005, -1498889924, -716521073, -263983575, -2042749120, -1263297029, 2060971911, -1666777591, 188198003, 251790886, 280390084, 1738016223, -580281801, 1831928083, -355653596, 1102400369, 2095795866, -294097927, 419052797, -1582812810, 0
	};
	q31_t q31_b_array[ARRAY_SIZE] = {
	204712319, 180144284, -209543243, 53916792, 197369355, 170830946, 1203514600, -312712536, 920743651, -1824625112, 420984875, 566536029, -506845364, -6857324, -434156189, -2142111505, 1045850978, -553910124, 824249774, -1488182567, -1675551882, -1925964935, 130855719, -1519925487, -589106798, 1494457749, -1565562513, -1262423706, -1230994795, -1088443954, 292519408, 1485212926, 242646787, -1088539142, -1274467679, 377739522, 159674802, -1547588366, -1949250075, -70691370, 781689702, -1835633981, 1942796846, -946887651, 848483564, -1548962935, 1870014462, 965663041, 1064259438, -383719640, -978783057, -944796566, 1430103113, -1260222873, -491040724, 1890727220, 2083502691, -556734811, -2113938357, -1585633018, 500105338, -886584662, 1336908666, -1311222963, 829306607, 910265989, 772979607, 626531703, 1646600062, -1937223716, -2024512853, -2067002399, -339307241, 1222434257, 1935277322, -231577250, -1724802316, 1907944900, 1658715575, -167516745, -58080523, 704490019, 1769573496, 32104716, 1064048689, -1318211013, 1016863918, 156537401, -1570152318, 131164953, 473324936, -196058652, -804227817, -9864755, 261520124, 1688883032, -1390111444, -522034107, 1274716973, 28982511, -1257583053, 1239694813, 1559794457, -1954406219, -416627738, -1691661573, 2039656472, -775687970, 729664130, 71135859, 2096190599, -1103089806, 1123796817, 694770500, -1976481918, -2134177767, -1583968644, -335906080, 2071961996, 1579203899, 262093988, 650393055, -338265896, -1505741655, 1175860682, 946357443, -1207168411, -225330030, -1176181106, 2011575645, -1754066324, -809543616, -1373368213, 358483112, 340851017, -997540864, -1584216501, 739788159, -1149806217, -1975988237, -1970552427, 1972302799, -448351628, 270309495, -2139626674, -2098878453, -1182495205, 2083627675, -610056538, -1743625393, 673599227, 1366000634, -1502388581, 1682967668, 42387805, 1022528321, -96259255, -151651019, 1907675374, -1465653629, 913779582, 199093513, -1083451962, 1172360491, -173772550, -1036446741, 2087691584, 954130802, -828357762, 916251036, 607400636, 1421070580, 1517590451, 979323974, -447508836, -1857041315, -1438039268, 2094707628, -1113865682, 1858121943, -1697925378, 1947565393, -2033040794, 826742982, -1017221207, -1265775408, 1775001649, -901031292, -1006552336, 28220675, 348700548, -2022106631, -1882248812, 2128053164, 447961767, 1419683607, -584893763, 1106977433, 486359498, 1533950699, 1837531408, 69590196, 1154641977, 1250545798, 505825431, 827243169, -632897439, -1841468473, 576227897, 1408476080, -251749351, -1814864257, -1767927418, -1694086470, -158656041, 1426194109, -1158397383, 896561495, 562232852, 973254663, -1206226163, -680189470, 522302066, -262726378, -74845893, -1057028022, 1845899344, 1161389957, -778331576, -11579864, 1225550271, -1500506478, 381609770, -1012049574, -1757206767, 96165946, 815148018, 265234274, 98201427, -826365919, -100542806, 1481517858, 1701987141, -1255526945, 611861026, -1118297781, 529286200, 1718060564, -6828272, -313800781, 1878684705, -2109937359, 732996262, 588183518, -872143020, -950440153, 0
	};
    /* clang-format on */
    float32_t f32_out_array[ARRAY_SIZE], f32_out_ref_array[ARRAY_SIZE];
    q7_t q7_out_array[ARRAY_SIZE], q7_out_ref_array[ARRAY_SIZE];
    q15_t q15_out_array[ARRAY_SIZE], q15_out_ref_array[ARRAY_SIZE];
    q31_t q31_out_array[ARRAY_SIZE], q31_out_ref_array[ARRAY_SIZE];
    float32_t f32_out, f32_out_ref;
    q7_t q7_out, q7_out_ref;
    q15_t q15_out, q15_out_ref;
    q31_t q31_out, q31_out_ref;
    q63_t q63_out, q63_out_ref;
    BENCH_INIT;
#if defined NEGATE || defined ENABLE_ALL
    // ****************************************   negate
    // ******************************* f32_negate
    BENCH_START(riscv_negate_f32);
    riscv_negate_f32(f32_a_array, f32_out_array, ARRAY_SIZE);
    BENCH_END(riscv_negate_f32);
    ref_negate_f32(f32_a_array, f32_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (fabs(f32_out_array[i] - f32_out_ref_array[i]) > DELTAF32) {
            BENCH_ERROR(riscv_negate_f32);
            printf("index: %d, expect: %f, actual: %f\n", i,
                   f32_out_ref_array[i], f32_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_negate_f32);

    // riscv_negate_q7.c
    BENCH_START(riscv_negate_q7);
    riscv_negate_q7(q7_a_array, q7_out_array, ARRAY_SIZE);
    BENCH_END(riscv_negate_q7);
    ref_negate_q7(q7_a_array, q7_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (abs(q7_out_array[i] - q7_out_ref_array[i]) > DELTAQ7) {
            BENCH_ERROR(riscv_negate_q7);
            printf("index: %d, expect: %x, actual: %x\n", i,
                   q7_out_ref_array[i], q7_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_negate_q7);

    // riscv_negate_q15.c
    BENCH_START(riscv_negate_q15);
    riscv_negate_q15(q15_a_array, q15_out_array, ARRAY_SIZE);
    BENCH_END(riscv_negate_q15);
    ref_negate_q15(q15_a_array, q15_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (abs(q15_out_array[i] - q15_out_ref_array[i]) > DELTAQ15) {
            BENCH_ERROR(riscv_negate_q15);
            printf("index: %d, expect: %x, actual: %x\n", i,
                   q15_out_ref_array[i], q15_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_negate_q15);

    // riscv_negate_q31.c
    BENCH_START(riscv_negate_q31);
    riscv_negate_q31(q31_a_array, q31_out_array, ARRAY_SIZE);
    BENCH_END(riscv_negate_q31);
    ref_negate_q31(q31_a_array, q31_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (labs(q31_out_array[i] - q31_out_ref_array[i]) > DELTAQ31) {
            BENCH_ERROR(riscv_negate_q31);
            printf("index: %d, expect: %x, actual: %x\n", i,
                   q31_out_ref_array[i], q31_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_negate_q31);
#endif
#if defined OFFSET || defined ENABLE_ALL
    // *************************************   offset
    // ********************************** f32_offset
    BENCH_START(riscv_offset_f32);
    riscv_offset_f32(f32_a_array, 100, f32_out_array, ARRAY_SIZE);
    BENCH_END(riscv_offset_f32);
    ref_offset_f32(f32_a_array, 100, f32_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (fabs(f32_out_array[i] - f32_out_ref_array[i]) > DELTAF32) {
            BENCH_ERROR(riscv_offset_f32);
            printf("index: %d, expect: %f, actual: %f\n", i,
                   f32_out_ref_array[i], f32_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_offset_f32);

    // riscv_offset_q7.c
    BENCH_START(riscv_offset_q7);
    riscv_offset_q7(q7_a_array, 100, q7_out_array, ARRAY_SIZE);
    BENCH_END(riscv_offset_q7);
    ref_offset_q7(q7_a_array, 100, q7_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (abs(q7_out_array[i] - q7_out_ref_array[i]) > DELTAQ7) {
            BENCH_ERROR(riscv_offset_q7);
            printf("index: %d, expect: %x, actual: %x\n", i,
                   q7_out_ref_array[i], q7_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_offset_q7);

    // riscv_offset_q15.c
    BENCH_START(riscv_offset_q15);
    riscv_offset_q15(q15_a_array, 100, q15_out_array, ARRAY_SIZE);
    BENCH_END(riscv_offset_q15);
    ref_offset_q15(q15_a_array, 100, q15_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (abs(q15_out_array[i] - q15_out_ref_array[i]) > DELTAQ15) {
            BENCH_ERROR(riscv_offset_q15);
            printf("index:%d, expect: %x, actual: %x\n", i,
                   q15_out_ref_array[i], q15_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_offset_q15);

    // riscv_offset_q31.c
    BENCH_START(riscv_offset_q31);
    riscv_offset_q31(q31_a_array, 100, q31_out_array, ARRAY_SIZE);
    BENCH_END(riscv_offset_q31);
    ref_offset_q31(q31_a_array, 100, q31_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (labs(q31_out_array[i] - q31_out_ref_array[i]) > DELTAQ31) {
            BENCH_ERROR(riscv_offset_q31);
            printf("index: %d, expect: %x, actual: %x\n", i,
                   q31_out_ref_array[i], q31_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_offset_q31);
#endif
#if defined SCALE || defined ENABLE_ALL
    // *************************************   scale ***************************
    // f32_scale
    BENCH_START(riscv_scale_f32);
    riscv_scale_f32(f32_a_array, 3.5, f32_out_array, ARRAY_SIZE);
    BENCH_END(riscv_scale_f32);
    ref_scale_f32(f32_a_array, 3.5, f32_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (fabs(f32_out_array[i] - f32_out_ref_array[i]) > DELTAF32) {
            BENCH_ERROR(riscv_scale_f32);
            printf("index: %d, expect: %f, actual: %f\n", i,
                   f32_out_ref_array[i], f32_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_scale_f32);

    // riscv_scale_q7.c
    BENCH_START(riscv_scale_q7);
    riscv_scale_q7(q7_a_array, 6, 7, q7_out_array, ARRAY_SIZE);
    BENCH_END(riscv_scale_q7);
    ref_scale_q7(q7_a_array, 6, 7, q7_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (abs(q7_out_array[i] - q7_out_ref_array[i]) > DELTAQ7) {
            BENCH_ERROR(riscv_scale_q7);
            printf("index: %d, expect: %x, actual: %x\n", i,
                   q7_out_ref_array[i], q7_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_scale_q7);

    // riscv_scale_q15.c
    BENCH_START(riscv_scale_q15);
    riscv_scale_q15(q15_a_array, 15, 15, q15_out_array, ARRAY_SIZE);
    BENCH_END(riscv_scale_q15);
    ref_scale_q15(q15_a_array, 15, 15, q15_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (abs(q15_out_array[i] - q15_out_ref_array[i]) > DELTAQ15) {
            BENCH_ERROR(riscv_scale_q15);
            printf("index: %d, expect: %x, actual: %x\n", i,
                   q15_out_ref_array[i], q15_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_scale_q15);

    // riscv_scale_q31.c
    BENCH_START(riscv_scale_q31);
    riscv_scale_q31(q31_a_array, 987746463, -1, q31_out_array, ARRAY_SIZE);
    BENCH_END(riscv_scale_q31);
    ref_scale_q31(q31_a_array, 987746463, -1, q31_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (labs(q31_out_array[i] - q31_out_ref_array[i]) > DELTAQ31) {
            BENCH_ERROR(riscv_scale_q31);
            printf("index: %d, expect: %x, actual: %x\n", i,
                   q31_out_ref_array[i], q31_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_scale_q31);
#endif
#if defined SHIFT || defined ENABLE_ALL
    // **************************************   shift
    // ************************************** riscv_shift_q7.c
    BENCH_START(riscv_shift_q7);
    riscv_shift_q7(q7_a_array, -3, q7_out_array, ARRAY_SIZE);
    BENCH_END(riscv_shift_q7);
    ref_shift_q7(q7_a_array, -3, q7_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (abs(q7_out_array[i] - q7_out_ref_array[i]) > DELTAQ7) {
            BENCH_ERROR(riscv_shift_q7);
            printf("index: %d, expect: %x, actual: %x\n", i,
                   q7_out_ref_array[i], q7_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_shift_q7);

    // riscv_shift_q15.c
    BENCH_START(riscv_shift_q15);
    riscv_shift_q15(q15_a_array, -3, q15_out_array, ARRAY_SIZE);
    BENCH_END(riscv_shift_q15);
    ref_shift_q15(q15_a_array, -3, q15_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (abs(q15_out_array[i] - q15_out_ref_array[i]) > DELTAQ15) {
            BENCH_ERROR(riscv_shift_q15);
            printf("index:%d expect: %x, actual: %x\n", i, q15_out_ref_array[i],
                   q15_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_shift_q15);

    // riscv_shift_q31.c
    BENCH_START(riscv_shift_q31);
    riscv_shift_q31(q31_a_array, -3, q31_out_array, ARRAY_SIZE);
    BENCH_END(riscv_shift_q31);
    ref_shift_q31(q31_a_array, -3, q31_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (labs(q31_out_array[i] - q31_out_ref_array[i]) > DELTAQ31) {
            BENCH_ERROR(riscv_shift_q31);
            printf("index:%d, expect: %d, actual: %d\n", i,
                   q31_out_ref_array[i], q31_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_shift_q31);
#endif
#if defined SUB || defined ENABLE_ALL
    // *************************************   sub
    // **************************************** riscv_sub_f32.c
    BENCH_START(riscv_sub_f32);
    riscv_sub_f32(f32_a_array, f32_b_array, f32_out_array, ARRAY_SIZE);
    BENCH_END(riscv_sub_f32);
    ref_sub_f32(f32_a_array, f32_b_array, f32_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (fabs(f32_out_array[i] - f32_out_ref_array[i]) > DELTAF32) {
            BENCH_ERROR(riscv_sub_f32);
            printf("i: %d, expect: %f, actual: %f\n", i, f32_out_ref_array[i],
                   f32_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_sub_f32);

    // riscv_sub_q7.c
    BENCH_START(riscv_sub_q7);
    riscv_sub_q7(q7_a_array, q7_b_array, q7_out_array, ARRAY_SIZE);
    BENCH_END(riscv_sub_q7);
    ref_sub_q7(q7_a_array, q7_b_array, q7_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (abs(q7_out_array[i] - q7_out_ref_array[i]) > DELTAQ7) {
            BENCH_ERROR(riscv_sub_q7);
            printf("index: %d, expect: %x, actual: %x\n", i,
                   q7_out_ref_array[i], q7_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_sub_q7);

    // riscv_sub_q15.c
    BENCH_START(riscv_sub_q15);
    riscv_sub_q15(q15_a_array, q15_b_array, q15_out_array, ARRAY_SIZE);
    BENCH_END(riscv_sub_q15);
    ref_sub_q15(q15_a_array, q15_b_array, q15_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (abs(q15_out_array[i] - q15_out_ref_array[i]) > DELTAQ15) {
            BENCH_ERROR(riscv_sub_q15);
            printf("index: %d, expect: %x, actual: %x\n", i,
                   q15_out_ref_array[i], q15_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_sub_q15);

    // riscv_sub_q31.c
    BENCH_START(riscv_sub_q31);
    riscv_sub_q31(q31_a_array, q31_b_array, q31_out_array, ARRAY_SIZE);
    BENCH_END(riscv_sub_q31);
    ref_sub_q31(q31_a_array, q31_b_array, q31_out_ref_array, ARRAY_SIZE);
    for (int i = 0; i < ARRAY_SIZE; i++)
        if (labs(q31_out_array[i] - q31_out_ref_array[i]) > DELTAQ31) {
            BENCH_ERROR(riscv_sub_q31);
            printf("index: %d, expect: %x, actual: %x\n", i,
                   q31_out_ref_array[i], q31_out_array[i]);
            test_flag_error = 1;
        }
    BENCH_STATUS(riscv_sub_q31);
#endif
    BENCH_FINISH;
    if (test_flag_error) {
        printf("test error apprears, please recheck.\n");
        return 1;
    } else {
        printf("all test are passed. Well done!\n");
    }
    return 0;
};
